Components.utils.import("resource://gre/modules/DbTerminal.jsm");
/*邮件数据自动加载*/
function OnInit(){
   dDeviceSqlite.onLoad();
   createMailList(getMailMessage());
}
/*获取数据库中的邮件信息*/
function getMailMessage(){
    if(!(dDeviceSqlite.initialized) ||! (dDeviceSqlite.dbStatus)){
        dDeviceSqlite.onLoad();
     }
     var statement = dDeviceSqlite.dbConnection.createStatement("SELECT * FROM td_email");
     var mailInfo = [{id:0 ,subject:"", from:"",date:""}];
     try{
        while(statement.executeStep()){
            mailInfo.push(
                    {id:statement.row.eId,
                     subject:statement.row.eSubject, 
                     from:statement.row.eFrom,
                     date:statement.row.eDate});
        }
    }finally{
        statement.reset();
    }
    return mailInfo;
}
/*邮件内容展示 tree*/
function createMailList(mailInfo){
   
    var tChild  = document.getElementById("terminalChildren");
    for (var i = 1; i < mailInfo.length; i++) {
        var titem = document.createElement('treeitem');
        var trow = document.createElement('treerow');
        //check
        var tcell0 = document.createElement('treecell');
        tcell0.setAttribute("id", ("treecell_0_"+i));
        trow.appendChild(tcell0);
        //subject
        var tcell1 = document.createElement('treecell');
        tcell1.setAttribute("id", ("treecell_1_"+i));
        tcell1.setAttribute('label', mailInfo[i].subject);
        trow.appendChild(tcell1);
        //from
        var tcell2 = document.createElement('treecell');
        tcell2.setAttribute("id", ("treecell_2_"+i));
        tcell2.setAttribute('label', mailInfo[i].from);
        trow.appendChild(tcell2);
        //date
        var tcell3 = document.createElement('treecell');
        tcell3.setAttribute("id", ("treecell_3_"+i));
        tcell3.setAttribute('label', mailInfo[i].date);
        trow.appendChild(tcell3);
        
        titem.appendChild(trow);
        tChild.appendChild(titem);
        }
    }
function GetThreadTree()
{
  return document.getElementById("threadTree");
}


